
#include "jncExpression.h"

#define RETREXPR(r, data, x)  (*(char**)&x)

static const char* regex[][3] = {
  { // char, signed char, unsigned char
    "(.[^()]*)\\((*[[:alnum:]]{CHR} ?)\\)", 
    "-? (.[^()]*)\\((*[[:alnum:]]{CHR} ?)\\)", 
    "[^-] (.[^()]*)\\((*[[:alnum:]]{CHR} ?)\\)"
  },
  { // short, signed short, unsigned short
    "(.[^()]*)\\((*[0-9]{SHT} ?)\\)", 
    "-? (.[^()]*)\\((*[0-9]{SHT} ?)\\)", 
    "[^-] (.[^()]*)\\((*[0-9]{SHT} ?)\\)"
  },
  { // int, signed int, unsigned int
    "(.[^()]*)\\((*[0-9]{5} ?)\\)", 
    "-? (.[^()]*)\\((*[0-9]{5} ?)\\)", 
    "[^-] (.[^()]*)\\((*[0-9]{5} ?)\\)"
  },
  { // long, signed long, unsigned long
    "(.[^()]*)\\((*[0-9]{LNG} ?)\\)", 
    "-? (.[^()]*)\\((*[0-9]{LNG} ?)\\)", 
    "[^-] (.[^()]*)\\((*[0-9]{LNG} ?)\\)"
  },
  { // jmfn0
    "(.[^()]*)\\{(.*)\\}",
    NULL,
    NULL
  },
  { // jmfn1
    "(.[^()]*)\\{(.*)\\}",
    NULL,
    NULL
  },
  { // jmfn2
    "(.[^()]*)\\{(.*)\\}",
    NULL,
    NULL
  },
  { // jmfn3
    "(.[^()]*)\\{(.*)\\}",
    NULL,
    NULL
  },
  { // jmfn4
    "(.[^()]*)\\{(.*)\\}",
    NULL,
    NULL
  },
  { // jmfn5
    "(.[^()]*)\\{(.*)\\}",
    NULL,
    NULL
  },
  { // jmfn6
    "(.[^()]*)\\{(.*)\\}",
    NULL,
    NULL
  },
  { // jmfn7
    "(.[^()]*)\\{(.*)\\}",
    NULL,
    NULL
  },
  { // jmfn8
    "(.[^()]*)\\{(.*)\\}",
    NULL,
    NULL
  },
  { // jmfn9
    "(.[^()]*)\\{(.*)\\}",
    NULL,
    NULL
  },
  { // jcmp
    "(.[^()]*)\\((.* ?)\\)",
    NULL,
    NULL
  },
  { // jbool
    "(.[^()]*)\\((*[01] ?)\\)",
    NULL,
    NULL
  },
  { // jvoid
    "(.*)",
    NULL,
    NULL
  },
  { // jdouble
    "(.[^()]*)\\((*-?[0-9]{DBL} ?)\\)",
    NULL,
    NULL
  },
  { // jfloat
    "(.[^()]*)\\((*-?[0-9]{5}\\.[0-9]{5} ?)\\)",
    NULL,
    NULL
  }
};

static const char* TypExprTable[] = {
  BOOST_PP_SEQ_ENUM(BOOST_PP_SEQ_FOR_EACH(RETREXPR, ~, REGEXP))
};

const char* getExpression(jncTypei typei)
{
  if(typei < 0 || typei >= BOOST_PP_SEQ_SIZE(REGEXP))
    return NULL;
  return TypExprTable[typei];
}
